package kiosk;

import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import javax.xml.datatype.XMLGregorianCalendar;
import server.Ticket;

/**
 *
 * @author Renato Rosa <2101076@my.ipleiria.pt>
 */
public class PrintableTicket implements Printable {

    private Ticket ticket;
    private Font bigFont = new Font("Trebuchet MS", Font.BOLD, 25);
    private Font smallFont = new Font("Trebuchet MS", Font.PLAIN, 8);

    public PrintableTicket(Ticket ticket) {
        this.ticket = ticket;
    }

    @Override
    public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
        if (pageIndex > 0) {
            return Printable.NO_SUCH_PAGE;
        }

        Graphics2D g2d = (Graphics2D) graphics;
        g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());

        // Ticket
        g2d.setFont(bigFont);
        g2d.drawString(ticket.getText(), 80, 40);

        g2d.setFont(smallFont);
        //g2d.drawString(ticket.getSubjectName(), 75, 50);
        
        //date and time
        XMLGregorianCalendar date = ticket.getCreationTime();
        String dateF = String.format("%02d/%02d/%04d %02d:%02d:%02d", date.getDay(), date.getMonth(), date.getYear(),
                    date.getHour(), date.getMinute(), date.getSecond());

        
        g2d.drawString(dateF, 72, 50);
        
        //footer
        g2d.drawString("Serviços académicos - Campus 2 - IPL", 40, 120);

        return Printable.PAGE_EXISTS;
    }
}
